<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="perm" uri="/WEB-INF/tld/perm.tld"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
	<script>var ctx="${ctx}";</script>
	<head>
	    <meta charset="utf-8">
	    <meta name="viewport" content="width=device-width, initial-scale=1.0">
	    <title>商户管理</title>
	    <meta name="keywords" content="体验,友好,高级管理台,易用,高性能,高扩展性,bootstrap框架,响应式后台">
	    <meta name="description" content="这是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">
	    <meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
		<meta http-equiv="expires" content="Wed, 26 Feb 209908:21:57 GMT"> 
	    
		<link rel="shortcut icon" href="favicon.ico"> 
		<link href="${ctx}/static/css/bootstrap.min.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/font-awesome.min.css?v=4.4.0?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/footable/footable.core.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/summernote/summernote.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/summernote/summernote-bs3.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/plugins/laypage/laypage.css?v=${static_version}"  rel="stylesheet">
		<link href="${ctx}/static/css/plugins/iCheck/custom.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/chosen/chosen.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/animate.min.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/js/plugins/layer/laydate/laydate.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/plugins/webuploader/webuploader.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/css/style.min.css?v=${static_version}/" rel="stylesheet">
		<link href="${ctx}/static/js/plugins/uploadify/uploadify.css?v=${static_version}/" rel="stylesheet">
	    
	</head>
	<body class="gray-bg">
    	<div class="ibox float-e-margins">
    		<div class="ibox-content">
                <form class="form-group" id="merchant_table_form">	
                	<input type="hidden" name="orderBy" value="create_date desc">
                	<input type="hidden" id="merchant-select-id" name="typeId" value="">
                	<div class="row">
                		<perm:hasPermission code="merchant/find">
                        <div class="col-md-2"><input name="keyword" type="text" placeholder="请输入关键字" class="form-control" /></div>
		     	  		<div class="col-md-4">
                            <div class="input-daterange input-group">
                                <input id="startTime" type="text" class="input-md form-control layer-date" placeholder="开始时间"  name="startTime">
					        	<span class="input-group-addon">至</span>
					        	<input id="endTime" type="text" class="input-md form-control layer-date" placeholder="结束时间"  name="endTime">
                            </div>
					    </div>
						<div class="col-md-2 col-sm-2">
							<select data-placeholder="选择企业类型" id="merchant-select-select" class="input-md form-control chosen-select" tabindex="4">
			                    <option value="">选所企业类型</option>
			                </select>
						</div>
						<div class="col-md-1 col-sm-2">
							<button id="merchant_table_search" type="button" class="btn btn-outline btn-block btn-primary">查询</button>
						</div>
						</perm:hasPermission>
						<perm:hasPermission code="merchant/insertGet">
					    <div class="col-md-1  col-sm-2 pull-right " style="display: none">
							<a  onclick="clickInsertGet()" class="btn btn-block btn-outline btn-primary">添加</a>
					    </div>
					    </perm:hasPermission>
                    </div>
                </form>
				<table id="merchant_table" data-action="${ctx}/merchant/find" data-datatable="true"  class="footable table table-stripped toggle-arrow-tiny">
				  	<thead>
					  	<tr>
							<th data-sort-ignore="true"  data-title="name" >商家名称</th>
<!-- 							<th data-sort-ignore="true"  data-title="logo" >商家logo</th> -->
							<th data-sort-ignore="true"  data-title="mobile" >联系方式</th>
							<th data-sort-ignore="true"  data-title="address" >地址</th>
<!-- 							<th data-sort-ignore="true"  data-title="description" >商家简介</th> -->
<!-- 							<th data-sort-ignore="true"  data-title="advantage" >商家优势</th> -->
<!-- 							<th data-sort-ignore="true"  data-title="license" >商家资质</th> -->
<!-- 							<th data-sort-ignore="true"  data-title="memberName" >商家绑定会员</th> -->
							<th data-sort-ignore="true"  data-title="typeName" >企业类型</th>
							<th data-sort-ignore="true"  data-title="createDate" data-formater="yyyy-MM-dd" data-type="datetime" data-hide="phone,tablet">创建时间</th>
							<th data-sort-ignore="true"  data-title="status"  data-type="enum" data-opt='{"0":"正常","1":"待审核","2":"已拒绝","3":"已锁定"}'>状态</th>
							<th data-sort-ignore="true"  data-title="reason" >操作结果</th>
			      	
						  	<th data-sort-ignore="true"  data-crudx="true" data-title='{"uid":"id"}' data-hide="phone">操作
			      			  <div style="display: none;" class="center hidden-phone">
								  	<perm:hasPermission code="merchant/upStatus">
			      			  			<button data-type='change' data-toge="status"  data-callback="modifyStatus" data-id=":uid" style="margin-left:3px;margin-top:3px" type="button" class="btn btn-primary btn-xs">启用/禁用</button>
							  		</perm:hasPermission>
								  	<perm:hasPermission code="merchant/upStatus">
			      			  			<button data-type='change' data-toge="status"  data-callback="successStatus" data-id=":uid" style="margin-left:3px;margin-top:3px" type="button" class="btn btn-primary btn-xs">启用/禁用</button>
							  		</perm:hasPermission>
								  	<perm:hasPermission code="merchant/upStatus">
			      			  			<button data-type='change' data-toge="status"  data-callback=failStatus data-id=":uid" style="margin-left:3px;margin-top:3px" type="button" class="btn btn-primary btn-xs">启用/禁用</button>
							  		</perm:hasPermission>
			      			  	 <perm:hasPermission code="merchant/updateGet">
			      			  	 	<button onclick="clickUpdateGet(this)" data-id=":uid" type="button" style="margin-left:3px;margin-top:3px" class="btn btn-xs btn-outline btn-info"><i class="fa fa-pencil"></i>&nbsp;更新</button>
			      			  	 </perm:hasPermission>
			      			  	 <perm:hasPermission code="merchant/findcomment">
			      			  	 	<button onclick="clickfindcomment(this)" data-id=":uid" type="button" style="margin-left:3px;margin-top:3px" class="btn btn-xs btn-outline btn-info"><i class="fa fa-eye"></i>&nbsp;留言</button>
			      			  	 </perm:hasPermission>
							  </div> 
		      		      	</th>
					  	</tr>
				  	</thead>
				  	<tbody>
				  	</tbody>
			  	</table>
			  	<div class="row">
			  		<div class="col-md-6" class="pull-left" id="page_left_text"></div>
			  		<div class="col-md-6"  id="page_text"></div>
			  	</div>
			</div>
		</div>
		
	<script src="${ctx}/static/js/jquery.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/bootstrap.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/footable/footable.all.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/validate/jquery.validate.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/validate/messages_zh.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/webuploader/webuploader.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/summernote/summernote.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/summernote/summernote-zh-CN.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/chosen/chosen.jquery.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/layer/laydate/laydate.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/iCheck/icheck.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/plugins/laypage/laypage.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/switchery/switchery.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/eModal.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/cookie.js?v=?v=${static_version}"></script>
	<script src="${ctx}/static/common/custom-datatable.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/content.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/contabs.min.js?v=${static_version}"></script>
	<script src="${ctx}/static/common/common.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/layer/layer.js?v=${static_version}"></script>
	<script src="${ctx}/static/js/plugins/uploadify/jquery.uploadify.js?v=${static_version}"></script>
	
	<script>
		$(document).ready(function() {
			init_page_datatable();
		});
		
		
		var modifyStatus=function(cData,cLable,row,togeColumn){
			console.log("---["+JSON.stringify(togeColumn)+"]");
			if(togeColumn["status"]===0){
				return '<button onclick="statusModify(this,3)" data-id=":uid" style="margin-left:3px;margin-top:3px" class="btn btn-outline btn-success btn-xs "><i class="fa fa-unlock-alt"></i>&nbsp;禁用</button>';
			}else if(togeColumn["status"]===3){
				return '<button onclick="statusModify(this,0)" data-id=":uid" style="margin-left:3px;margin-top:3px" class="btn btn-outline btn-success btn-xs"><i class="fa fa-unlock-alt"></i>&nbsp;启用</button>';
			}
		}
		var successStatus=function(cData,cLable,row,togeColumn){
			console.log("---["+JSON.stringify(togeColumn)+"]");
			if(togeColumn["status"]===1){
				return '<button onclick="statusModify(this,1)" data-id=":uid" style="margin-left:3px;margin-top:3px" class="btn btn-outline btn-warning btn-xs"><i class="fa fa-check"></i>&nbsp;通过</button>';
			}
		}
		var failStatus=function(cData,cLable,row,togeColumn){
			console.log("---["+JSON.stringify(togeColumn)+"]");
			if(togeColumn["status"]===1){
				return '<button onclick="failStatusmodify(this,2)" data-id=":uid" style="margin-left:3px;margin-top:3px" class="btn btn-outline btn-warning btn-xs"><i class="fa fa-warning"></i>&nbsp;驳回</button>';
			}
		}

		var statusModify=function(me,status){
			var text="用户管理?";
			 if(status===0){
				 text="确定解除锁定?";
			 }else if(status===1){
				 text="确定通过审核?";
				 status=0;
			 }else if(status===3){
				 text="确定锁定用户?";
			 }
			 $.confirm({
			    text:text,
			    confirm: function() {
			    	$.ajax({  
			    		url:'${ctx}/merchant/upStatus',  
	   					data:{
	   						id:$(me).data("id"),
	   						status:status
	   					},   
						type: 'POST',
   	 					dataType:'json',  
   	 					success:function(response){
   	 						if(response.code==0){
   	 							eModal.close();
   	 							$("#merchant_table_search").click();
   	 						}else{
   	 						    $.confirm({cancelButton: "关   闭",title: '提示',text:"重置用户密码错误!"});
   	 						}
   	 					}  
   	 			    });  
			    },
			    cancel: function() {
			        return true;
			    }
			});
		}

		

		var failStatusmodify=function(me){
			layer.prompt({
				  formType: 2,
				  title: '拒绝原因，必须填写！'
				}, function(value){
					 $.ajax({
				   	        url: "${ctx}/merchant/upStatus",
				   	        title:"aaa",
				   	        loading:true,
				   	 		data:{				
				   	 			reason:value,
								status:2,		
								id:$(me).data("id")
							},   
							type: 'POST',
							success:function(response){
	   	 						if(response.code==0){
	   	 							eModal.close();
	   	 						$("#merchant_table_search").click();
	   	 						}else{
	   	 						    $.confirm({cancelButton: "关   闭",title: '提示',text:"重置用户密码错误!"});
	   	 						}
	   	 					}  
				   	    });
				  layer.msg('已驳回！', {icon: 1});
				});
			 // layer.close(index);
		}
		
		var clickfindcomment=function(me){
			location.href="${ctx}/merchant/findcomment?id="+$(me).data("id");
		}
		var clickUpdateGet=function(me){
			eModal.ajax({
	   	        url: "${ctx}/merchant/updateGet?id="+$(me).data("id"),
	   	        title:'修改商户',
	   	        loading:true,
	   	        subtitle: '',
	   	        buttons: [
	   	            {text:'保存',style:'info',close:false,click:function(){
		   	 			if (!jQuery.checkall(true)) return;
		   	     		var images=[];
		   	     		var licimages=[];
		   	 			$("#logodiv img").each(function(){
		   					images.push($(this).attr("src"));
		   				})
		   				$("#licensediv .upimg").each(function(){
		   					licimages.push($(this).attr("src"));
		   				})
	   	 		    	$.ajax({  
	   	 					url:'${ctx}/merchant/update',  
	   	 					data:{
								name:$("#name").val(),			
								logo:$("#logo").val(),						
								logo:images.toString(),							
								mobile:$("#mobile").val(),							
								address:$("#address").val(),							
								description:$("#description").val(),							
								advantage:$("#advantage").val(),							
								license:licimages.toString(),							
								typeId:$("#typeId").val(),							
								id:$("#id").val()
							},   
							type: 'POST',
	   	 					dataType:'json',  
	   	 					success:function(response){
	   	 						if(response.code==0){
	   	 							eModal.close();
	   	 							$("#merchant_table_search").click();
	   	 						}else if(response.message==1){
		 							  layer.msg('该商户名称已被使用！', {icon: 5});
	   	 						}else if(response.message==2){
		 							  layer.msg('该手机号已被注册！', {icon: 5});
	   	 						}
	   	 					}  
	   	 			    }); 
	   	            }},{text: '取消', style: 'danger', close: false, click:function(){
	   	            	eModal.close();
	   	            }}
	   	        ],
	   	    });
		}
		
		var clickInsertGet=function(){
			eModal.ajax({
	   	        url: "${ctx}/merchant/insertGet",
	   	        title:'添加商户',
	   	        loading:true,
	   	        subtitle: '',
	   	        buttons: [
	   	            {text: '保存',style:'info',close:false,click:function(){
		   	 			if (!jQuery.checkall(true)) return;
	   	            	var images=[];
		   	     		var licimages=[];
		   	 			$("#logodiv img").each(function(){
		   					images.push($(this).attr("src"));
		   				})
		   				$("#licensediv img").each(function(){
		   					licimages.push($(this).attr("src"));
		   				})
	   	 		    	$.ajax({  
	   	 					url:'${ctx}/merchant/add',  
	   	 					data:{
								name:$("#name").val(),								
								status:1,									
								logo:images.toString(),								
								mobile:$("#mobile").val(),							
								address:$("#address").val(),							
								description:$("#description").val(),							
								advantage:$("#advantage").val(),							
								license:licimages.toString(),							
								typeId:$("#typeId").val(),							
								id:$("#id").val()
							},   
							type: 'POST',
	   	 					dataType:'json',  
	   	 					success:function(response){
	   	 						if(response.code==0){
	   	 							eModal.close();
	   	 							$("#merchant_table_search").click();
	   	 						}else if(response.code==1){
		 							  layer.msg(response.message, {icon: 5});
	   	 						}
	   	 					}  
	   	 			    }); 
	   	            }},{text: '取消', style: 'danger', close: false, click:function(){
	   	            	eModal.close();
	   	            }}
	   	        ],
	   	    });
		}

		$(function(){
		
			jQuery.searchFormInit();
		    
		    $.ajax({  
				url:'${ctx}/merchantType/list',  		 					
				type: 'POST',
				dataType:'json',  
				success:function(response){
					if(response.code==0){
						var html=[];
						var data=response.data||[];
						for(var i=0;i<data.length;i++){
							html.push('<option value="'+data[i].id+'">'+data[i].name+'</option>');
						}
						$("#merchant-select-select").append(html.join(""));
						$("#merchant-select-select").trigger("chosen:updated");
					}
				 }  
		     });
			
			 $("#merchant-select-select").chosen({width:'100%'}).change(function(event) {
				$("#merchant-select-id").val($(event.target).val());
			 });
		    
		});
	</script>
	
	</body>
</html>